﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using System.Text;
using Model;
using DB;

/// <summary>
/// Activity_Award_informationService 的摘要说明
/// </summary>
/// 
namespace ArchivesManagement
{
    public class ActivityAwardInformationService
    {
        string sql = string.Empty;

        public ActivityAwardInformationService()
        {
        }

        //根据档案编号得到活动奖励信息
        public IList<ActivityAwardInformation> GetActivityAwardInformationByFileNumber(string fileNumber)
        {
            IList<ActivityAwardInformation> activityAwardInformations = new List<ActivityAwardInformation>();
            sql = "select * from ActivityAwardInformation";
            if (fileNumber.ToString() != "0")
            {
                sql += "where FileNumber=" + fileNumber.ToString();
            }
            using (SqlDataReader dr = DB.DBHelper.Exc(sql))
            {
                while (dr.Read())
                {
                    ActivityAwardInformation activityAwardInformation = new ActivityAwardInformation();

                    activityAwardInformation.AwardDiscription = Convert.ToString(dr["AwardDiscription"]);
                    activityAwardInformation.AwardType = Convert.ToString(dr["AwardType"]);
                    activityAwardInformations.Add(activityAwardInformation);
                    //activityAwardInformations.Add(activityAwardInformation);
                }
            }
            return activityAwardInformations;
        }

        //得到档案编号
        public string  GetFileNumber()
        {
            //ArchivesDestinationRecord archivesDestinationRecord= new ArchivesDestinationRecord();
            string  fileNumber = string .Empty;
            sql = "select * from ActivityAwardInformation where FileNumber=" + fileNumber.ToString();

            SqlDataReader dr = DB.DBHelper.Exc(sql);
            if (dr.Read())
            {

                fileNumber = Convert.ToString(dr["FileNumber"]);


            }
            return fileNumber;
        }

        //得到活动奖励信息集合
        public IList<ActivityAwardInformation> GetActivityAwardInformation()
        {
            IList<ActivityAwardInformation> activityAwardInformations = new List<ActivityAwardInformation>();
            sql = "select * from ActivityAwardInformation";

            using (SqlDataReader dr = DB.DBHelper.Exc(sql))
            {
                while (dr.Read())
                {
                    ActivityAwardInformation activityAwardInformation = new ActivityAwardInformation();
                    activityAwardInformation.ID = Convert.ToInt32(dr["ID"]);
                    activityAwardInformation.FileNumber = Convert.ToString(dr["FileNumber"]);
                    activityAwardInformation.AwardDiscription = Convert.ToString(dr["AwardDiscription"]);
                    activityAwardInformation.AwardType = Convert.ToString(dr["AwardType"]);
                    activityAwardInformations.Add(activityAwardInformation);
                }
            }
            return activityAwardInformations;
        }

        //根据奖励ID得到客房实体对象
        public ActivityAwardInformation GetActivityAwardInformationByID(int id)
        {
            ActivityAwardInformation activityAwardInformation = new ActivityAwardInformation();
            sql = "select * from ActivityAwardInformation where ID=" + id.ToString();
            using (SqlDataReader dr = DB.DBHelper.Exc(sql))
            {
                while (dr.Read())
                {
          
                    activityAwardInformation.FileNumber = Convert.ToString(dr["FileNumber"]);
                    activityAwardInformation.AwardDiscription = Convert.ToString(dr["AwardDiscription"]);
                    activityAwardInformation.AwardType = Convert.ToString(dr["AwardType"]);
                }
            }
            return activityAwardInformation;
        }

           //根据奖励ID删除活动奖励信息
        public void DeleteActivityAwardInformationByStudentId(int id) 
        {
            sql = "delete from ActivityAwardInformation where ID=" + Convert.ToString(id);
            DB.DBHelper.ExecuteCommand(sql);
        }

        //修改活动奖励信息
        public int  ModifyActivityAwardInformation(ActivityAwardInformation activityAwardInformation)
        {
            int id;
            StringBuilder updateActivityAwardInformation = new StringBuilder();
            updateActivityAwardInformation.Append("update ActivityAwardInformation set");
            updateActivityAwardInformation.Append("FileNumber=" + "'" + activityAwardInformation.FileNumber+ "'");
            updateActivityAwardInformation.Append("AwardDiscription="+"'"+activityAwardInformation.AwardDiscription+"'");
            updateActivityAwardInformation.Append("AwardDiscription=" + "'" + activityAwardInformation.AwardType + "'");
            updateActivityAwardInformation.Append("where FileNumber=" + activityAwardInformation.FileNumber);
            sql = updateActivityAwardInformation.ToString();
            id=DB.DBHelper.ExecuteCommand(sql);
            return id;
        }
        /// <summary>
        /// 增加活动奖励信息
        /// </summary>
        /// <returns></returns>
        public int AddActivityAwardInformation(ActivityAwardInformation activityAwardInformation)
        {
            int id=0;
            StringBuilder addActivityAwardInformation = new StringBuilder();
            addActivityAwardInformation.Append("insert into ActivityAwardInformation(FileNumber,AwardDiscription,AwardType) values(" +
                "'" + activityAwardInformation.FileNumber + "','" + activityAwardInformation.AwardDiscription + "','" + activityAwardInformation.AwardType + "')select @@IDENTITY");
            sql = addActivityAwardInformation.ToString();
            id = DB.DBHelper.ExecuteCommand(sql);
            return id;
        }

        public int GetIDByFileNmuber(string  fileNumber)
        {
            int id = 0;
            sql = "select ID from ActivityAwardInformation where FileNumber=" + "'" + fileNumber + "'";
            using(SqlDataReader dr = DB.DBHelper.Exc(sql))
            {
                if (dr.Read())
                {
                    id = Convert.ToInt32(dr["ID"]);
                }
            }
            return id;
        }

        public string  GetFileNumberByID(int id)
        {
            string  fileNumber = string .Empty;
            sql = "select FileNumber from ID=" + "'" + id + "'";
            using(SqlDataReader dr = DB.DBHelper.Exc(sql))
            {
                if (dr.Read())
                {
                    fileNumber = Convert.ToString(dr["FileNumber"]);
                }
            }
            return fileNumber;
        }

        
    }
}